import { Route, Redirect } from "react-router-dom";
import { isAuth } from "@/utils";
export const AuthRoute = ({ component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) => {
        let isLogin = isAuth();
        if (isLogin) {
          return <Component></Component>;
        } else {
          return (
            <Redirect
              to={{
                // 重定向时要重定向到哪个页面的地址
                pathname: "/login",
                state: {from:props.location.pathname},
              }}
            ></Redirect>
          );
        }
      }}
    ></Route>
  );
};
